package com.lin.chapter11;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;

public class WebSocketServerInitializer extends ChannelInitializer<Channel> {
	@Override
	protected void initChannel(Channel ch) throws Exception {
		ch.pipeline().addLast(new HttpServerCodec(),
				new HttpObjectAggregator(65536),
				new WebSocketServerProtocolHandler("/websocket"));
	}

	public static final class TextFrameHandler extends SimpleChannelInboundHandler<TextWebSocketFrame>{

		@Override
		protected void channelRead0(ChannelHandlerContext ctx, TextWebSocketFrame msg) throws Exception {
			// TODO: 2018/1/7
		}
	}

	public static final class BinaryFrameHandler extends SimpleChannelInboundHandler<BinaryFrameHandler>{

		@Override
		protected void channelRead0(ChannelHandlerContext ctx, BinaryFrameHandler msg) throws Exception {
			// TODO: 2018/1/7
		}
	}

	public static final class ContinuationFrameHandler extends SimpleChannelInboundHandler<ContinuationFrameHandler>{

		@Override
		protected void channelRead0(ChannelHandlerContext ctx, ContinuationFrameHandler msg) throws Exception {
			// TODO: 2018/1/7  
		}
	}
}
